<?php
namespace app\wxpro\controller;
use think\Db;
use think\Controller;
use app\service\wechatService;
use think\Log;
class Vehicle extends Controller{
	
	public function test(){
		$openid="oC2YJwDZNdmP2bqLd95WkakhgzCI";
		$parking_name="西溪永乐城停车场";
		$msg="欢迎您进入".$parking_name;
		$in_time=date('Y-m-d H:i:s');
		$car_number="浙D61S21";
		$url="http://www.zzfq.zfbzhsq.com/index/Tplmsg/cararrive?openid=".$openid."&parking_name=".$parking_name."&car_number=".$car_number."&in_time=".$in_time;
		$res=file_get_contents($url);
		var_dump($res);
	}
	public function wugan(){
		$openid=request()->get("openid");
		$data['appid'] = 'wx352362f198d9c56b';//公众账号ID
        $data['mch_id'] = '1484539292';//商户号
        $data['sub_appid'] = 'wx6e64e3c7372be385';//小程序id  
		$data['sub_mch_id']="1511534341";// 1500219082
        $data['nonce_str'] = (new wechatService())->createNoncestr();//随机字符串
        
		
		$data['trade_scene']="PARKING";
		$data['sign_type']="HMAC-SHA256";//HMAC-SHA256
		$data['openid']=$openid;
        $wxkey = 'asdfaASDFASDFASFasfsadf6546A84SA';    
        $data['sign'] = (new wechatService())->MakeSign($data,$wxkey);//签名
		$arr["status"]="1";
		$arr["data"]=$data;
		return json_encode($arr);
	}
	
	public function arrive(){
       
        $data['appid'] = 'wx352362f198d9c56b';//公众账号ID
        $data['mch_id'] = '1484539292';//商户号
        $data['sub_appid'] = 'wx6e64e3c7372be385';//小程序id  
		$data['sub_mch_id']="1500219082";//  1511534341
        $data['nonce_str'] = (new wechatService())->createNoncestr();//随机字符串
        //$data['out_trade_no'] ="20190823110523123456";//商户订单号
        $data['version'] = "2.0";//总金额
		$data['trade_scene']="PARKING";//浙AAAAA1
		$data['sign_type']="HMAC-SHA256";//HMAC-SHA256
		$data['scene_info']='{"scene_info":{"start_time":"20190823110523","plate_number":"浙D61S21","free_time":"1200","car_type":"大型车","parking_name":"西溪永乐城停车场"}}';
        
        $wxkey = 'asdfaASDFASDFASFasfsadf6546A84SA';    
        $data['sign'] = (new wechatService())->MakeSign($data,$wxkey);//签名
		echo "<pre>";
		var_dump($data);
		$yzl=(new wechatService())->ToXml($data);
		
        $xml = (new wechatService())->ToXml($data);
				
        $url = 'https://api.mch.weixin.qq.com/vehicle/partnerpay/notification';
        $payInfo = (new wechatService())->post_curl_data($url,$xml);
        $payInfo =json_encode(simplexml_load_string($payInfo, 'SimpleXMLElement', LIBXML_NOCDATA));
		var_dump($payInfo);
        $payInfo = json_decode( $payInfo, true);
        
        var_dump($payInfo);
	}
    
	//用户状态查询
	public function querystate(){
        $data['appid'] = 'wx352362f198d9c56b';//公众账号ID
		$data['sub_appid'] = 'wx6e64e3c7372be385';//小程序id 
        $data['mch_id'] = '1484539292';//商户号
		$data['sub_mch_id']="1500219082";//
        $data['nonce_str'] = (new wechatService())->createNoncestr();//随机字符串
		$data['sign_type']="HMAC-SHA256";
		
		$data['trade_scene']="PARKING";
        $data['jump_scene'] ="";//商户跳转的业务场景，不传默认是小程序，也支持APP和公众号H5跳转APP:通过APP跳转 H5:通过公众号H5跳转
        $data['version'] = "2.0";//版本号
		$data['plate_number']="浙D61S21";//浙D61S21
		
		
		
        $wxkey = 'asdfaASDFASDFASFasfsadf6546A84SA';    
        $data['sign'] = (new wechatService())->MakeSign($data,$wxkey);//签名
        
        $xml = (new wechatService())->ToXml($data);
        
        $url = 'https://api.mch.weixin.qq.com/vehicle/partnerpay/querystate';
        $payInfo = (new wechatService())->post_curl_data($url,$xml);
        
        $payInfo = json_decode(json_encode(simplexml_load_string($payInfo, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        echo "<pre>";
        var_dump($payInfo);
	}
	
	//申请扣款
	public function payapply(){
		
		$data['appid'] = 'wx352362f198d9c56b';//公众账号ID
		$data['sub_appid'] = 'wx6e64e3c7372be385';//小程序id 
        $data['mch_id'] = '1484539292';//商户号
		$data['sub_mch_id']="1500219082";
        $data['nonce_str'] = (new wechatService())->createNoncestr();//随机字符串
		$data['sign_type']="HMAC-SHA256";
		
        $data['body'] ="停车代扣";//商户跳转的业务场景，不传默认是小程序，也支持APP和公众号H5跳转APP:通过APP跳转 H5:通过公众号H5跳转
        $data['out_trade_no'] = "20190823110523123441";//版本号
		$data['total_fee']=1;
		$data['spbill_create_ip'] = $_SERVER["REMOTE_ADDR"];//终端IP
		$data['notify_url'] = 'https://www.fqsc.zfbzhsq.com/index/order/wxnotice';//通知url
		$data['trade_type']='PAP';
		$data['version']='2.0';
		$data['trade_scene']="PARKING";
		$data['scene_info']='{"scene_info":{"start_time":"20190823110523","	
end_time":"20190823130623","plate_number":"浙D61S21","free_time":"0","charging_time":"1260","car_type":"大型车","parking_name":"西溪永乐城停车场"}}';
        
        $wxkey = 'asdfaASDFASDFASFasfsadf6546A84SA';    
        $data['sign'] = (new wechatService())->MakeSign($data,$wxkey);//签名
        
        $xml = (new wechatService())->ToXml($data);
        
        $url = 'https://api.mch.weixin.qq.com/vehicle/partnerpay/payapply';
		$time1=time();
		echo $time1;echo "<br/>";
		
        $payInfo = (new wechatService())->post_curl_data($url,$xml);
        
        $payInfo = json_decode(json_encode(simplexml_load_string($payInfo, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
		$time2=time();
		echo $time2;echo "<br/>";
		
		echo ($time2-$time1);echo "<br/>";
        echo "<pre>";
        var_dump($payInfo);
	}
}